﻿@model Sharp.WebBooter.Areas.CMS.Models.UserGroupIndexViewModel

<section class="content-header">
    <h1>
        用户组管理
    </h1>
    <ol class="breadcrumb">
        <li><a href="@Url.Action("Index", "Home")"><i class="fa fa-home"></i> 首页</a></li>
        <li class="active">用户</li>
    </ol>
</section>


<section class="content">
    <div class="row">
        <div class="col-lg-12">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <div class="dataTable-tools btn-group">
                        @Html.Bootstrap().LinkButton("添加", ToolBarIco.Create).Click("window.app.loadUI('" + @Url.Action("Create") + "')").Route(Url.Action("Create"))
                        @Html.Bootstrap().LinkButton("删除", ToolBarIco.Delete).Click("window.app.deleteItem('example','" + @Url.Action("Delete") + "')").Route(Url.Action("Delete"))

                        @Html.Bootstrap().LinkButton("权限", ToolBarIco.Permission).Click("ShowWindow(); return false;").Route(Url.Action("Create"))
                        @Html.Bootstrap().LinkButton("刷新", ToolBarIco.Refresh).Click("window.app.search();")
                    </div>
                    <div class="box-tools">
                        
                        <div class="input-group input-group-sm SearchArea" style="width: 150px;">
                            <input type="text" name="Title" class="form-control pull-right" placeholder="搜索">

                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default" onclick="window.app.search();"><i class="fa fa-search"></i></button>
                            </div>
                        </div>
                    </div>
                    <div class="box-body no-padding">

                    
                        <div class="table-responsive">
                            <table id="example" class="table table-bordered table-striped table-hover dataTable text-center" width="100%"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<script type="text/javascript">
    $(document).ready(function () {

        $('#example').dataTable({
            "serverSide": true,
            "ajax": {
                "url": "@Url.Action("GetPaged")",
                "type": "POST"
            },
            "columnDefs": [
                { "searchable": false, sortable: false, "orderable": false, "targets": [-1, 0, 1, 2] }, { "sClass": "editableCol", "aTargets": [1] }
            ],
            columns: [
                { title: '<label class="checkbox m-l-12 m-t-none m-b-none i-checks"><input type="checkbox" /><i></i></label>', data: function (row, type, set) { return '<label class="checkbox m-l-12 m-t-none m-b-none i-checks"><input type="checkbox" name="cellCheckbox" value="' + row.id + '" /><i></i></label>'; }, "bStorable": false, width: 30 },

                {
                    title: "名称", data: function (row) {
                        return '<a class="auto" href="javascript:window.app.loadUI(\'@Url.Action("Edit")/' + row.id + '\')">' + row.title + '</a>';
                    }, width: 160
                },
                { title: "备注", data: 'remark', "sClass": "left" },
                { title: "创建时间", data: function (row) { return new Date(row.checkInTime).format('yyyy-MM-dd HH:mm:ss') }, width: 140, "sClass": "center" }
            ]
        });
    });
    function ShowWindow() {

        var ids = new Array();

        $("#example tbody tr").each(function (x) {

            var checkbox = $(this).find("td:eq(0) input");

            if (checkbox.length > 0 && checkbox.prop('checked')) {
                ids.push(checkbox.val());
                return;
            }
        });

        if (ids.length === 0) {
            window.app.message("请选中一项。");
            return;
        }
        if (ids.length > 1) {
            window.app.message("只能选中一项。");
            return;
        }

        parent.$('#ajaxModal').remove();

        var $remote = "@Url.Action("Index", "Permission")" + "?owner=userGroup&ownerId=" + ids[0]
          , $modal = $('<div id="ajaxModal">用来做容器</div>');
        parent.$('body').append($modal);

        $modal.load($remote, function () {
            var newmodal = $modal.children("div").modal();
            newmodal.modal('show');
        });
    }
</script>